<template>
  <div>
    <FormContainer title="基本信息">
      <template #default>
        <el-descriptions :column="2" border>
          <template slot="extra">
            <el-button
              type="danger"
              icon="el-icon-money"
              size="small"
              @click="handleOperate('refund')"
            >
              <!--   :disabled="
                data.contractConfirmStatus !== 3 ||
                data.status === 3 ||
                data.payMoney !== data.contractMoney
              " -->
              退费
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-user"
              size="small"
              :disabled="data.contractConfirmStatus !== 0"
            >
              设置班主任
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              :disabled="data.contractConfirmStatus !== 0"
            >
              修改合同信息
            </el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="small"
              :disabled="data.contractConfirmStatus !== 0"
            >
              删除合同
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-user"
              size="small"
              @click="handleConfirmPay('apply')"
            >
              提交审核
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-user"
              size="small"
              @click="handleConfirmPay('cashierApply')"
            >
              出纳审核
            </el-button>
            <el-button
              type="danger"
              icon="el-icon-user"
              size="small"
              @click="handleConfirmPay('cashierUnApply')"
            >
              出纳驳回审核
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-user"
              size="small"
              @click="handleConfirmPay('principalApprove')"
            >
              校长审核
            </el-button>
          </template>
          <el-descriptions-item>
            <template slot="label"> 编号 </template>
            {{ data.contractCode }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 学员 </template>
            {{ data.customerName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 校区 </template>
            {{ data.campusName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 合同状态 </template>
            {{
              data.status === 0
                ? "执行中"
                : data.status === 1
                ? "停课"
                : data.status === 2
                ? "冻结"
                : data.status === 3
                ? "已完结"
                : ""
            }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 合同类型 </template>
            {{ data.contractTypeName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 合同属性 </template>
            {{
              data.contractAttribute === 0
                ? "新签"
                : data.contractAttribute === 1
                ? "续签"
                : data.contractAttribute === 2
                ? "赠送"
                : ""
            }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 开始日期 </template>
            {{ data.beginTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 周数 </template>
            {{ data.week }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 是否推荐 </template>
            {{
              data.isReferrer === 0 ? "否" : data.isReferrer === 1 ? "是" : ""
            }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 推荐人 </template>
            {{ data.referrerName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 年级 </template>
            {{ formatGrade(data.grade) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 续签可能 </template>
            {{
              data.isSustain === 0
                ? "小"
                : data.isSustain === 1
                ? "中"
                : data.isSustain === 2
                ? "大"
                : ""
            }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 签约者 </template>
            {{ data.signerName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 签约日期 </template>
            {{ data.signerTime }}
          </el-descriptions-item>
          <el-descriptions-item :span="2">
            <template slot="label"> 备注 </template>
            {{ data.note }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 合同确认状态 </template>
            {{
              data.contractConfirmStatus == 0
                ? "新合同"
                : data.contractConfirmStatus == 1
                ? "待出纳确认"
                : data.contractConfirmStatus == 2
                ? "出纳已确认"
                : data.contractConfirmStatus == 3
                ? "校长已确认"
                : data.contractConfirmStatus == 4
                ? "已锁定"
                : ""
            }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 班主任 </template>
            {{ data.techerName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 出纳确认时间 </template>
            {{ data.cashierApproveTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 校长确认时间 </template>
            {{ data.principalApproveTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 总金额 </template>
            {{ data.contractMoney }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 已支付金额 </template>
            {{ data.payMoney }}
          </el-descriptions-item>
        </el-descriptions>
      </template>
    </FormContainer>
    <FormContainer title="合同明细">
      <template #default>
        <el-descriptions :column="2" border>
          <template slot="extra">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="small"
              :disabled="data.contractAttribute !== 0"
              @click="handleOperate('spd')"
            >
              添加合同明细
            </el-button>
          </template>
        </el-descriptions>
        <el-table :data="data.sysContractLabelList" border stripe>
          <el-table-column label="序号" type="index" align="center" />
          <el-table-column
            label="科目"
            align="center"
            prop="subjectClassName"
          />
          <el-table-column label="明细类型" align="center" width="200">
            <template slot-scope="scope">
              <span>{{
                scope.row.labelType == 0
                  ? "新签"
                  : scope.row.labelType == 1
                  ? "续签"
                  : "赠送"
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="年级"
            prop="trackingRecords"
            align="center"
            width="200"
          >
            <template>
              <span>{{ formatGrade(data.grade) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="单价"
            prop="price"
            align="center"
            width="200"
          />
          <el-table-column
            label="课时"
            prop="subjectClassTime"
            align="center"
            width="200"
          />
          <el-table-column
            label="小计"
            prop="totalPrice"
            align="center"
            width="200"
          />
          <el-table-column
            label="奖学金折扣"
            prop="scholarshipDiscount"
            align="center"
            width="200"
          />
          <el-table-column label="续科奖" prop="" align="center" width="200" />
          <el-table-column
            label="操作"
            align="center"
            width="150"
            fixed="right"
          >
            <template #default="{ row }">
              <el-button
                type="text"
                size="small"
                @click="handleDeleteContract(row.id)"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </FormContainer>
    <FormContainer title="业绩分配">
      <template #default>
        <el-descriptions :column="2" border>
          <template slot="extra">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="small"
              @click="handleOperate('add')"
            >
              添加业绩分配
            </el-button>
          </template>
        </el-descriptions>
        <el-table :data="data.sysContractSpdList" border stripe>
          <el-table-column label="序号" type="index" align="center" />
          <el-table-column label="员工" align="center" prop="userName" />
          <el-table-column label="百分比" prop="percentage" align="center" />
          <el-table-column label="金额" prop="price" align="center" />
          <el-table-column
            label="操作"
            align="center"
            width="150"
            fixed="right"
          >
            <template #default="{ row }">
              <el-button type="text" size="small" @click="handleDelete(row.id)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </FormContainer>
    <FormContainer title="付费记录">
      <template #default>
        <el-descriptions :column="2" border>
          <template slot="extra">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="small"
              @click="handleOperate('pay')"
            >
              添加付费记录
            </el-button>
          </template>
        </el-descriptions>
        <el-table :data="data.sysContractPayLabelList" border stripe>
          <el-table-column label="序号" type="index" align="center" />
          <el-table-column label="类型" align="center">
            <template #default="{ row }">
              <span v-if="row.payType === 0">合同款</span>
              <span v-else-if="row.payType === 1">首付款</span>
              <span v-else>尾款</span>
            </template>
          </el-table-column>
          <el-table-column label="支付金额" prop="payMoney" align="center" />
          <el-table-column label="是否支付" align="center">
            <template #default="{ row }">
              <span v-if="row.isPay === 1">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column label="支付方式" align="center">
            <template #default="{ row }">
              <span v-if="row.payMethod === 0">现金</span>
              <span v-else-if="row.payMethod === 1">刷卡</span>
              <span v-else-if="row.payMethod === 2">转账</span>
            </template>
          </el-table-column>
          <el-table-column label="Pos单号" prop="posNo" align="center" />
          <el-table-column
            label="操作"
            align="center"
            width="150"
            fixed="right"
          >
            <template #default="{ row }">
              <el-button
                type="text"
                size="small"
                @click="handleDeletePay(row.id)"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </FormContainer>
    <FormContainer title="合同操作记录">
      <template #default>
        <el-table :data="data.sysContractLogList" border stripe>
          <el-table-column label="序号" type="index" align="center" />
          <el-table-column label="用户" prop="createBy" align="center" />
          <el-table-column label="时间" prop="createTime" align="center" />
          <el-table-column label="操作" prop="operate" align="center" />
        </el-table>
      </template>
    </FormContainer>

    <el-dialog
      :title="dialog.title"
      :visible.sync="dialog.visible"
      width="50%"
      center
      @close="handleClose"
    >
      <template v-if="dialog.type == 'refund'">
        <FormContainer title="合同明细">
          <template #default>
            <el-table :data="dialog.data.tableData" border stripe>
              <el-table-column label="序号" type="index" align="center" />
              <el-table-column
                label="科目"
                align="center"
                prop="subjectClassName"
              />
              <el-table-column label="明细类型" align="center">
                <template slot-scope="scope">
                  <span>{{
                    scope.row.labelType == 0
                      ? "新签"
                      : scope.row.labelType == 1
                      ? "续签"
                      : "赠送"
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="单价" prop="price" align="center" />
              <el-table-column
                label="课时"
                prop="subjectClassTime"
                align="center"
              />
              <el-table-column
                label="已用课时"
                prop="duringClassTime"
                align="center"
              />
              <el-table-column
                label="已排课时"
                prop="notDuringClassTime"
                align="center"
              />
              <el-table-column
                label="剩余课时(可退)"
                prop="remainingClassTime"
                align="center"
              />
              <el-table-column label="退费课时" align="center" min-width="150">
                <template #default="{ row }">
                  <el-input-number
                    v-model="row.refund"
                    controls-position="right"
                    :min="0"
                    :max="row.remainingClassTime"
                  />
                </template>
              </el-table-column>
            </el-table>

            <div class="refundNote">* 如果是全退，赠送课时也要退</div>

            <div class="demo-input-suffix">
              收取管理费：
              <el-input-number
                v-model="dialog.data.controllerMoney"
                controls-position="right"
                :min="0"
              />
            </div>
          </template>
        </FormContainer>
      </template>
      <template v-else-if="dialog.type == 'spd'">
        <el-form
          :model="dialog.data"
          label-width="140px"
          :rules="rules"
          ref="contractForm"
        >
          <el-form-item label="科目" prop="subjectClassId">
            <el-select
              v-model="dialog.data.subjectClassId"
              placeholder="请选择科目"
              class="form-select"
            >
              <el-option
                v-for="item in classOptions"
                :key="item.dictCode"
                :label="item.dictLabel"
                :value="item.dictCode"
                :disabled="item.status == 1"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="课时" prop="subjectClassTime">
            <el-input-number
              v-model="dialog.data.subjectClassTime"
              controls-position="right"
              :min="1"
              class="form-input"
            />
          </el-form-item>
          <el-form-item label="单价" prop="price">
            <el-input-number
              v-model="dialog.data.price"
              controls-position="right"
              :min="1"
              class="form-input"
            />
          </el-form-item>
          <el-form-item label="合同属性" prop="labelType">
            <el-select
              v-model="dialog.data.labelType"
              placeholder="请选择合同属性"
              clearable
              class="form-select"
            >
              <el-option label="新签" :value="0" />
              <el-option label="续费" :value="1" />
              <el-option label="赠送" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="奖学金折扣" prop="scholarshipDiscount">
            <el-input-number
              v-model="dialog.data.scholarshipDiscount"
              controls-position="right"
              :min="0"
              class="form-input"
            />
          </el-form-item>
        </el-form>
      </template>
      <template v-else-if="dialog.type == 'pay'">
        <el-form
          :model="dialog.data"
          label-width="140px"
          :rules="payRules"
          ref="payForm"
        >
          <el-form-item label="合同编号">
            <el-input
              v-model="dialog.data.contractCode"
              class="form-input"
              readonly
            />
          </el-form-item>
          <el-form-item label="合同总金额">
            <el-input
              v-model="dialog.data.contractMoney"
              class="form-input"
              readonly
            />
          </el-form-item>
          <el-form-item label="剩余金额">
            <el-input
              v-model="dialog.data.remainingMoney"
              class="form-input"
              readonly
            />
          </el-form-item>
          <el-form-item label="类型" prop="payType">
            <el-select
              v-model="dialog.data.payType"
              placeholder="请选择类型"
              clearable
              class="form-select"
            >
              <el-option label="合同款" :value="0" />
              <el-option label="首付款" :value="1" />
              <el-option label="尾款" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="支付金额" prop="payMoney">
            <el-input-number
              v-model="dialog.data.payMoney"
              controls-position="right"
              :min="1"
              :max="dialog.data.remainingMoney"
              class="form-input"
            />
          </el-form-item>
          <el-form-item label="是否支付" prop="isPay">
            <el-select
              v-model="dialog.data.isPay"
              placeholder="请选择是否支付"
              clearable
              class="form-select"
            >
              <el-option label="是" :value="1" />
              <el-option label="否" :value="0" />
            </el-select>
          </el-form-item>
          <el-form-item label="支付方式" prop="payMethod">
            <el-select
              v-model="dialog.data.payMethod"
              placeholder="请选择支付方式"
              clearable
              class="form-select"
            >
              <el-option label="现金" :value="0" />
              <el-option label="刷卡" :value="1" />
              <el-option label="转账" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="Pos单号" prop="posNo">
            <el-input
              v-model="dialog.data.posNo"
              clearable
              placeholder="请输入Pos单号"
              class="form-input"
            />
          </el-form-item>
        </el-form>
      </template>
      <template v-else-if="dialog.type == 'add'">
        <p>合同金额：{{ dialog.data.money }}</p>

        <el-row
          :gutter="20"
          v-for="(item, index) in dialog.data.data"
          :key="index"
          style="margin: 10px 0"
        >
          <el-col :span="4">
            <userSelect v-model="item.userId" placeholder="请选择教师" />
          </el-col>
          <el-col :span="4">
            <el-input
              v-model="item.percentage"
              placeholder="请输入百分比"
              @input="changePrice(item)"
            />
          </el-col>
          <el-col :span="4">
            <el-input v-model="item.price" placeholder="请输入金额" />
          </el-col>
        </el-row>
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import _ from "lodash";

import {
  getContract,
  delContractDetail,
  addContractPay,
  delContractPay,
  cashierApply,
  cashierUnApply,
  principalApprove,
  submitApply,
  refund,
  addPay,
  delPay,
} from "@/api/system/contract";
import campusSelect from "@/components/Select/campusSelect.vue";
import userSelect from "@/components/Select/userSelect.vue";

export default {
  data() {
    return {
      data: {},

      dialog: {
        visible: false, // 控制对话框的显示与隐藏
        data: {},
        title: "", // 对话框标题
        type: "", // 对话框类型，
      },
      rules: {
        subjectClassId: [
          { required: true, message: "请选择科目", trigger: "change" },
        ],
        subjectClassTime: [
          { required: true, message: "请输入课时", trigger: "blur" },
          { type: "number", min: 1, message: "课时必须大于0", trigger: "blur" },
        ],
        price: [
          { required: true, message: "请输入单价", trigger: "blur" },
          { type: "number", min: 1, message: "单价必须大于0", trigger: "blur" },
        ],
        labelType: [
          { required: true, message: "请选择合同属性", trigger: "change" },
        ],
        scholarshipDiscount: [
          { required: true, message: "请输入奖学金折扣", trigger: "blur" },
          { type: "number", min: 0, message: "折扣不能小于0", trigger: "blur" },
        ],
      },
      payRules: {
        payType: [{ required: true, message: "请选择类型", trigger: "change" }],
        payMoney: [
          { required: true, message: "支付金额不能为空", trigger: "blur" },
          {
            type: "number",
            min: 1,
            message: "支付金额必须大于0",
            trigger: "blur",
          },
        ],
        isPay: [
          { required: true, message: "请选择是否支付", trigger: "change" },
        ],
        payMethod: [
          { required: true, message: "请选择支付方式", trigger: "change" },
        ],
        posNo: [{ required: false, message: "请输入Pos单号", trigger: "blur" }],
      },

      classOptions: [],
    };
  },
  components: {
    campusSelect,
    userSelect,
  },
  mounted() {
    const query = this.$route.query;
    if (query.id) this.getData(query.id);

    this.getClassOptions();
  },
  methods: {
    getData(id) {
      getContract(id).then((res) => {
        if (res.code === 200) {
          console.log(res);
          this.data = res.data;
        } else {
          this.$message.error(res.msg || "获取客户信息失败");
        }
      });
    },
    /** 查询科目选项 */
    getClassOptions() {
      this.getDicts("sys_subject_class").then((response) => {
        this.classOptions = response.data;
        console.log(this.classOptions);
      });
    },

    handleConfirmPay(type) {
      const { id } = this.data;
      if (type == "apply") {
        this.$confirm("此操作将提交审核此条数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          submitApply({ id }).then((res) => {
            if (res.code == 200) {
              this.$message.success("提交审核通过");
              this.getData(this.$route.query.id); // 刷新合同数据
              return;
            }
          });
        });
      } else if (type === "cashierApply") {
        this.$confirm("此操作将审核此条数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          cashierApply({ id }).then((res) => {
            if (res.code == 200) {
              this.$message.success("出纳审核通过");
              this.getData(this.$route.query.id); // 刷新合同数据
              return;
            }
          });
        });
      } else if (type === "cashierUnApply") {
        this.$confirm("此操作将审核此条数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          cashierUnApply({ id }).then((res) => {
            if (res.code == 200) {
              this.$message.success("出纳审核未通过");
              this.getData(this.$route.query.id); // 刷新合同数据
              return;
            }
          });
        });
      } else if (type === "principalApprove") {
        this.$confirm("此操作将审核此条数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          principalApprove({ id }).then((res) => {
            if (res.code == 200) {
              this.$message.success("校长审核成功");
              this.getData(this.$route.query.id); // 刷新合同数据
              return;
            }
          });
        });
      } else {
        this.$message.error("未知操作类型");
        return;
      }
    },

    handleOperate(type) {
      if (type === "refund") {
        this.dialog.title = "退费操作";
        this.dialog.type = "refund";
        this.dialog.data = {
          tableData: this.data.sysContractLabelList,
        };
      } else if (type === "spd") {
        this.dialog.title = "添加合同明细";
        this.dialog.type = "spd";
      } else if (type === "pay") {
        this.dialog.title = "添加付费记录";
        this.dialog.type = "pay";
        this.dialog.data = {
          contractCode: this.data.contractCode,
          contractMoney: this.data.contractMoney,
          remainingMoney: this.data.remainingMoney,
          subjectClassTime: 0,
          price: 0,
          labelType: 0,
          scholarshipDiscount: 0,
        };
      } else if (type === "add") {
        this.dialog.title = "添加业绩分配";
        this.dialog.type = "add";
        this.dialog.data = {
          money: this.data.contractMoney,
          data: [{ id: 1 }, { id: 2 }, { id: 3 }],
        };
      } else {
        this.$message.error("未知操作类型");
        return;
      }

      this.dialog.visible = true;
    },

    handleConfirm() {
      if (this.dialog.type == "spd") {
        this.$refs["contractForm"].validate((valid) => {
          if (valid) {
            AddReport({
              ...this.dialog.data,
              contractId: this.data.id,
            }).then((res) => {
              if (res.code === 200) {
                this.$message.success("合同明细添加成功");
                this.dialog.visible = false;
                this.getData(this.$route.query.id); // 刷新合同数据
              } else {
                this.$message.error(res.msg || "添加合同明细失败");
              }
            });
          }
        });
      } else if (this.dialog.type == "pay") {
        addContractPay({
          ...this.dialog.data,
          contractId: this.data.id,
        }).then((res) => {
          if (res.code === 200) {
            this.$message.success("付费记录添加成功");
            this.dialog.visible = false;
            this.getData(this.$route.query.id); // 刷新合同数据
          } else {
            this.$message.error(res.msg || "添加付费记录失败");
          }
        });
      } else if (this.dialog.type == "refund") {
        const contractRefundLabelList = _.map(
          this.dialog.data.tableData,
          (item) => {
            return {
              contractLabelId: item.id,
              refundClassTime: item.refund,
            };
          }
        );
        const { id: contractId } = this.data;
        const { controllerMoney } = this.dialog.data;
        refund({ contractId, contractRefundLabelList, controllerMoney }).then(
          (res) => {
            if (res.code === 200) {
              this.$message.success("添加退费成功");
              this.dialog.visible = false;
              this.getData(this.$route.query.id); // 刷新合同数据
            } else {
              this.$message.error(res.msg || "添加退费失败");
            }
          }
        );
      } else if (this.dialog.type == "add") {
        const payData = _.filter(
          this.dialog.data.data.map((item) => ({
            userId: item.userId,
            percentage: item.percentage,
            price: item.price,
            contractId: this.data.id,
          })),
          (item) => item.userId && item.percentage && item.price
        );

        addPay(payData).then((res) => {
          if (res.code === 200) {
            this.$message.success("业绩分配添加成功");
            this.dialog.visible = false;
            this.getData(this.$route.query.id); // 刷新合同数据
          } else {
            this.$message.error(res.msg || "添加业绩分配失败");
          }
        });
      } else {
        this.$message.error("未知操作类型");
      }
    },

    handleClose() {
      this.dialog.visible = false;
      this.dialog.type = "";
      this.dialog.title = "";
      this.dialog.trackingForm = {};
      this.dialog.reservationForm = {};
    },
    // 删除合同明细
    handleDeleteContract(id) {
      delContractDetail(id).then((res) => {
        if (res.code === 200) {
          this.$message.success("跟踪记录删除成功");
          this.getData(this.data.customerId); // 刷新客户数据
        } else {
          this.$message.error(res.msg || "删除跟踪记录失败");
        }
      });
    },
    // 删除付费记录
    handleDeletePay(id) {
      delContractPay(id).then((res) => {
        if (res.code === 200) {
          this.$message.success("跟踪记录删除成功");
          this.getData(this.data.customerId); // 刷新客户数据
        } else {
          this.$message.error(res.msg || "删除跟踪记录失败");
        }
      });
    },
    // 删除业绩分配
    handleDelete(id) {
      delPay(id).then((res) => {
        if (res.code === 200) {
          this.$message.success("业绩分配删除成功");
          this.getData(this.data.customerId); // 刷新客户数据
        } else {
          this.$message.error(res.msg || "删除业绩分配失败");
        }
      });
    },

    formatGrade(grade) {
      const gradeOpiton = [
        { value: 0, label: "小一" },
        { value: 1, label: "小二" },
        { value: 2, label: "小三" },
        { value: 3, label: "小四" },
        { value: 4, label: "小五" },
        { value: 5, label: "小六" },
        { value: 6, label: "初一" },
        { value: 7, label: "初二" },
        { value: 8, label: "初三" },
        { value: 9, label: "高一" },
        { value: 10, label: "高二" },
        { value: 11, label: "高三" },
        { value: 12, label: "高四" },
      ];
      return _.find(gradeOpiton, { value: grade })?.label || "未知年级";
    },

    changePrice(item) {
      item.price = ((item.percentage / 100) * this.dialog.data.money).toFixed(
        2
      );
    },
  },
};
</script>
<style scoped lang="scss">
.form {
  &-input {
    width: 400px;
  }
  &-select {
    width: 400px;
  }

  &-date-picker {
    width: 400px;
  }
}
.refundNote {
  margin: 20px 0;
  color: red;
  font-size: 18px;
}
</style>
